class Solution:
    def backspaceCompare(self, s: str, t: str) -> bool:
        data1=list(s)
        data2=list(t)
        while len(data2)+len(data1)>0:
            if self.getLast(data1)==self.getLast(data2):
                continue
            else:
                return False
        return True
    def getLast(self,data:list):
        if len(data)==0:
            return ""
        a=data.pop(-1)
        count=-1
        if a=='#':
            count=1
        while count>=0:
            if len(data)==0:
                return ""
            a=data.pop(-1)
            if a=='#':
                count+=1
            else:
                count-=1
        return a

if __name__ == '__main__':
    Solution().backspaceCompare("xywrrmp",
                                "xywrrmu#p")

